define(["dijit/_WidgetBase",
        "dijit/_TemplatedMixin",
        "dojo/_base/declare",
        "dojo/text!./AjaxWidget/templates/AjaxWidget.html",
        "dojo/_base/xhr",
        "dojo/on"], 
		function(_WidgetBase,_TemplatedMixin, declare, template, xhr, on) {
	
return declare("AjaxWidget",[_WidgetBase,_TemplatedMixin],
	{
		maxResults: 10,
		timeOut: 3000,
		url: null,
		callback: null,
		label: "Search",
		templateString: template,
		_search: function(searchValue, maxResults, callback, url, timeOut) { 		
	    	callback(dojo.xhrPost({
		        url: url,
		        headers: { "Accept": "application/json" },
		        handleAs: "json",
		        timeout: timeOut,
		        content: {
		            searchName: searchValue,
		            maxResults: maxResults
		        }
	        }));
	    },
	    postCreate: function(){
	        this.inherited(arguments);
	        on(this.inputNode, "keyup", function(e) {
	        	this._search(this.inputNode.value,this.maxResults,this.callback,this.url,this.timeOut);
	        }.bind(this));
	    } 
	});
	
}); 